package com.nineclock.sign.controller;

import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.sign.dto.SignInfoDTO;
import com.nineclock.sign.dto.SignResponseDTO;
import com.nineclock.sign.dto.SignRsponseListDTO;
import com.nineclock.sign.pojo.SignInfo;
import com.nineclock.sign.service.SignInfonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping
@Api(value = "签到管理接口", tags = "签到服务")
public class SignInfoController {

    @Autowired
    private SignInfonService signInfonService;

    /**
     * 接口名称：PC: 查询签到列表
     * Tag ：签到服务
     * 接口路径：GET/sign/sign
     */
    @ApiOperation("查询签到列表")
    @GetMapping("sign")
    public Result<PageResult<SignInfoDTO>> querySigns(@RequestParam String startTime, @RequestParam String endTime,
                                                      @RequestParam(defaultValue = "10") Integer pageSize,
                                                      @RequestParam(defaultValue = "1") Integer page) {
        PageResult<SignInfoDTO> signInfoDTOS = signInfonService.querySigns(startTime, endTime, page, pageSize);
        return Result.success(signInfoDTOS);

    }

    /**
     * 接口名称：PC: 导出签到列表
     * Tag ：签到服务
     * 接口路径：GET/sign/export
     */
    @ApiOperation("导出签到列表")
    @GetMapping("export")
    public void exportSignInfo(String startTime, String endTime) throws Exception {
        signInfonService.exportSignInfo(startTime,endTime);
    }

    /*
    * 获取员工指定日期签到记录列表
    * */
    @GetMapping("/listSignAllUser")
    @ApiOperation(value = "查询员工指定日期签到记录列表")
    public Result<List<SignRsponseListDTO>> listSignAllUser(@RequestParam String dateStr){
        List<SignRsponseListDTO> signAllUser = signInfonService.listSignAllUser(dateStr);
        return Result.success(signAllUser);
    }

    /*
    * 查询当前登录用户某月的签到记录
    * */
    @GetMapping("/pagingSignCurrentUserByMonth")
    @ApiOperation("查询当前登录用户某月的签到记录")
    public Result<List<SignResponseDTO>> pagingSignCurrentUserByMonth(@RequestParam String dateStr){
        List<SignResponseDTO>  signResponseDTOList = signInfonService.pagingSignCurrentUserByMonth(dateStr);
        return Result.success(signResponseDTOList);
    }
}
